package com.cskaoyan.config;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

@Component
public class MarketSessionManger extends DefaultWebSessionManager {
    private static final String MARKET_ADMIN_TOKEN = "X-CskaoyanMarket-Admin-Token";

    private static final String MARKET_WX_TOKEN = "X-CskaoyanMarket-Token";

    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest req = (HttpServletRequest) request;
        String sessionId = req.getHeader(MARKET_ADMIN_TOKEN);
        if (sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }

        String sessionId2 = req.getHeader(MARKET_WX_TOKEN);

        if (sessionId2 != null && !"".equals(sessionId2)) {
            return sessionId2;
        }
        return super.getSessionId(request,response);
    }
}
